package com.topboya.linker.ui.presenter;

import com.topboya.linker.R;
import com.topboya.linker.api.ApiRetrofit;
import com.topboya.linker.model.response.MyNoticeListResponse;
import com.topboya.linker.model.response.VisitTypeResponse;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.view.NotifyView;
import com.topboya.linker.ui.view.VisiTypeView;
import com.topboya.linker.utils.LogUtils;
import com.topboya.linker.utils.UIUtils;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


public class MyNotifyPresenter extends BasePresenter<NotifyView> {
    private static final String TAG = "VisiTypePresenter：";

    public MyNotifyPresenter(BaseActivity context) {
        super(context);

    }

     public void getMyNoticeList(String pageNo) {

        mContext.showWaitingDialog(UIUtils.getString(R.string.please_wait));
        ApiRetrofit.getInstance().getMyNoticeList(pageNo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(myNoticeListResponse -> {
                    String success = myNoticeListResponse.getMeta().getSuccess();
                    mContext.hideWaitingDialog();
                    if (null != success && Boolean.parseBoolean(success)) {

                        MyNoticeListResponse.Data mynoticelist = myNoticeListResponse.getData();

                        getView().getMyNoticeList(mynoticelist);
                    }
                }, this::loginError);
    }

    public void getNoticeList(String pageNo) {

        mContext.showWaitingDialog(UIUtils.getString(R.string.please_wait));
        ApiRetrofit.getInstance().getNoticeList(pageNo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(noticeListResponse -> {
                    String success = noticeListResponse.getMeta().getSuccess();
                    mContext.hideWaitingDialog();
                    if (null != success && Boolean.parseBoolean(success)) {

                        MyNoticeListResponse.Data mynoticelist = noticeListResponse.getData();
                        getView().getNoticeList(mynoticelist);

                    }
                }, this::loginError);
    }
    private void loginError(Throwable throwable) {

        LogUtils.v(throwable.getLocalizedMessage());
        UIUtils.showToast(throwable.getLocalizedMessage());
        LogUtils.v(TAG + "loginError:" + throwable.getLocalizedMessage());
        mContext.hideWaitingDialog();
    }


}
